//
//  HWFriendHeaderV.m
//  HomeWork
//
//  Created by apple on 2017/10/25.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HWFriendHeaderV.h"
#import "HWUserInfo.h"
@interface HWFriendHeaderV()

/** 用户图片 */
@property (strong, nonatomic) UIImageView *profileImgV;
/** 用户头像 */
@property (strong, nonatomic) UIImageView *iconV;
/** 用户名称 */
@property (strong, nonatomic) UILabel *nameL;

@end

@implementation HWFriendHeaderV

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupSubviews];
        [self layoutUI];
        
    }
    return self;
}

- (void)setupSubviews{
    
    UIImageView *profileImgV = [[UIImageView alloc] init];
    self.profileImgV = profileImgV;
    profileImgV.backgroundColor = [UIColor grayColor];
    [self addSubview:profileImgV];
    
    UILabel *nameL = [[UILabel alloc] init];
    self.nameL = nameL;
    [self addSubview:nameL];
    nameL.chainFont(FONT(13)).chainTextColor(UIColorFromRGB(0xffffff));
    
    UIImageView *iconV = [[UIImageView alloc] init];
    self.iconV = iconV;
    [self addSubview:iconV];
    self.iconV.layer.borderColor = [UIColor whiteColor].CGColor;
    self.iconV.layer.borderWidth = 2;
}

- (void)layoutUI{
    [self.profileImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(self);
        make.bottom.mas_equalTo(-30);
    }];
    
    [self.iconV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-15);
        make.width.height.mas_equalTo(70);
    }];
    
    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.iconV.mas_left).offset(-10);
        make.bottom.mas_equalTo(self.profileImgV.mas_bottom).offset(-10);
    }];
}

- (void)setUserInfo:(HWUserInfo *)userInfo{
    _userInfo = userInfo;
    
    self.nameL.chainText(userInfo.username);
    [self.profileImgV setImageWithUrl:userInfo.profileImage];
    [self.iconV setImageWithUrl:userInfo.avatar placeholderImage:PlaceImage];

}

@end
